﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.Interception.PolicyInjection.Pipeline;

namespace NCP.Core.IoC
{
    public class OperLogHandler : ICallHandler
    {
        private ILog logger = LogManager.GetLogger(typeof(OperLogHandler));
        public int Order { get; set; }

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            string name = input.MethodBase.DeclaringType.Name;
            if (input.MethodBase.DeclaringType.IsGenericType)
                name = input.MethodBase.DeclaringType.GetGenericArguments()[0].Name;
            string paramStr = "";
            for (int i = 0; i < input.Arguments.Count; i++)
            {
                paramStr += string.Format("{0}:{1},", input.Arguments.GetParameterInfo(i), input.Arguments[i]);
            }
            string msg = string.Format("调用方法：{0}；参数：{1};", input.MethodBase.Name, paramStr);
            return getNext()(input, getNext);
        }
    }
}
